package com.cskaoyan.wordmemorize.controller.app;

import com.cskaoyan.wordmemorize.auth.SaUserCheckPermission;
import com.cskaoyan.wordmemorize.auth.StpKit;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.app.UserVocBookStatisticsDTO;
import com.cskaoyan.wordmemorize.service.UserPrivilegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user/priviledge/current")
public class UserPriviledgeCurrentController {

    @Autowired
    UserPrivilegeService userPrivilegeService;

    @SaUserCheckPermission("current:book")
    @GetMapping("{bookId}/statistics")
    public Result<UserVocBookStatisticsDTO> getVocBookStatistics(@PathVariable("bookId") Long bookId){
        long userId = StpKit.USER.getLoginIdAsLong();
        UserVocBookStatisticsDTO selectedBookStatistics = userPrivilegeService.getSelectedBookStatistics(userId, bookId);
        return Result.ok(selectedBookStatistics);
    }
}
